package org.gl.training.planner.model;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;

@Entity
@Table(name = "user_types")
public class UserTypes {

	@Id
	@Column(name = "Id")
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;

	@Column(name = "UserType")
	private String userType;

	@ManyToMany(mappedBy = "userTypesList", fetch = FetchType.LAZY)
	private List<User> userList;

	public static final UserTypes ADMIN = new UserTypes(1, "Admin");

	public static final UserTypes USER = new UserTypes(2, "User");

	public UserTypes(Integer id, String userType) {
		super();
		this.id = id;
		this.userType = userType;
	}

	public UserTypes() {
		super();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((userList == null) ? 0 : userList.hashCode());
		result = prime * result
				+ ((userType == null) ? 0 : userType.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserTypes other = (UserTypes) obj;

		return new EqualsBuilder().append(id, other.getId())
				.append(userType, other.getUserType()).isEquals();
	}

}
